package com.xiangxiao.rpan.storage.controller;

import com.xiangxiao.rpan.storage.constant.ResponseCode;
import com.xiangxiao.rpan.storage.constant.ResponseMessage;
import com.xiangxiao.rpan.storage.dto.JsonObject;
import com.xiangxiao.rpan.storage.service.StorageSourceService;
import com.xiangxiao.rpan.storage.vo.StorageSourceVo;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @auther xiangxiao
 * @email 573768011@qq.com
 * @data 2023/6/30 16:43
 */
@Slf4j
@RestController
@RequestMapping("/api/storage")
public class StorageController {
  private static Logger logger = LoggerFactory.getLogger(StorageController.class);
  @Autowired
  private StorageSourceService storageSourceService;

  @GetMapping("/list")
  public JsonObject StorageList() {
    try {
      List<StorageSourceVo> storageList = storageSourceService.findAllEnableOrderByOrderNum();
      return new JsonObject(ResponseMessage.QUERY_STORAGE_LIST_SUECCESS, ResponseCode.OK, storageList);
    } catch (Exception e) {
      e.printStackTrace();
      return new JsonObject(ResponseMessage.QUERY_STORAGE_README_LIST_FAILED, ResponseCode.FAIL);
    }
  }
}
